package com.duoketech.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class PageUtil {

    public String toUpperCase(String v){
        return v.toUpperCase();
    }

    public static double fengToYuan(int feng){

        return (feng*1.0/100);
    }

    public static int yuanToFeng(double yuan){
        return (int)(yuan*100);
    }

    public static double g2Kg(int g){
        return g/1000.0;
    }

    public static int kg2G(double kg){
        return (int)(kg*1000);
    }

    public static String split(String[] array){
        if(array==null || array.length<=0){
            return "";
        }
        StringBuffer sb = new StringBuffer();
        for (String s:array) {
            sb.append(s);
            sb.append(",");
        }
        String result = sb.toString();
        result = result.substring(0,result.lastIndexOf(","));
        return result;
    }

    public static String formatDataYYMMDD(Date date){
        return DateUtils.formateData(date,DateUtils.YYMMDD_FORMAT);
    }

    public static String formatDataYYMMDDHHMMSS(Date date){
        return DateUtils.formateData(date,DateUtils.YYMMDD_DETAIL_FORMAT);
    }

    public static List<String > imgs(String imgs){
        List<String> imgArray = new ArrayList<String>();
        if(StringUtils.isEmpty(imgs)){
            return imgArray;
        }

        JSONArray array = JSONArray.parseArray(imgs);
        for (Object o:array){
            JSONObject j = (JSONObject)o;
            imgArray.add(j.getString("url"));
        }
        return imgArray;
    }
}
